package com.yjd.comm.base.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.ServletUtil;

/**
 * @ClassName: BaseInterceptor
 * @Description: 拦截器基类
 * @author ready likun_557@163.com
 * @date 2014-8-19 下午2:16:14
 */
public abstract class BaseInterceptor extends HandlerInterceptorAdapter {
	
	public final static String BASENOURLFILE = "basenourl.txt";
	/**
	 * This implementation always returns <code>true</code>.
	 */
	@SuppressWarnings("unchecked")
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
	    throws Exception {
		if(FrameUtil.isValidate(FrameUtil.newArrayList(BASENOURLFILE), ServletUtil.getRquestUriNotContainContextPath(request))){
			return true;
		}else{
			return this.doPreHandle(request, response, handler);
		}
	}
	public abstract boolean doPreHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		    throws Exception;
	/**
	 * @Title: urlIsNeedValidate
	 * @Description: 判断url是否需要验证
	 * @param @param requestUrl
	 * @param @return 设定文件
	 * @return boolean 返回类型
	 * @throws
	 */
	protected boolean urlIsNeedValidate(String requestUrl) {
		return !FrameUtil.isValidate(this.getUrlFiles(), requestUrl);
	}

	protected List<String> getUrlFiles(){
		return null;
	}
}
